home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ9207.ZIP / AVKCAPT.ZIP / ACRECT.C < prev    next >
C/C++ Source or Header  |  1992-03-11  |  5KB  |  128 lines

  1. //-------------------------------------------------------------------------
  2. //            ActionMedia II Programmer's Toolkit
  3. //            
  4. //            Windows Motion Capture Sample Program
  5. //
  6. // Application:    AvkCapt.exe
  7. // Module Name:    acrect.c
  8. //
  9. // description:    Convert a Windows RECT's physical screen coordintes into 
  10. //                an AVK BOX according to the AVK View's resolution.
  11. //
  12. // Copyright Intel Corp. 1991, 1992
  13. // All Rights Reserved.
  14. //
  15. //-------------------------------------------------------------------------
  16. //
  17. // Exported functions from this module:
  18. //
  19. //        WinRect2AvkBox
  20. //
  21. //-------------------------------------------------------------------------
  22. #include <windows.h>
  23. #define    ACRECT_NOEXTERNS    1
  24. #include "avkcapt.h"
  25.  
  26. //-------------------------------------------------------------------------
  27. //    Macro to scale physical screen resolution to AVK View resolution.
  28. //    The physical screen coordinate is multiplied by the conversion
  29. //    delta which is arrived at by dividing the AVK View resolution by the
  30. //    physical screen resolution. The conversion is done in double precision and
  31. //    the resulting value, truncated to an integer, is the AVK View coordinate.
  32. //    
  33. //    Usage is as follows:
  34. //
  35. //        xAvkRes = SCREEN2AVK(xPhysRes, xDelta)
  36. //        yAvkRes = SCREEN2AVK(yPhysRex, yDelta)
  37. //
  38. //-------------------------------------------------------------------------
  39.  
  40. #define    SCREEN2AVK(r, d)    (int)((double)(r) * (double)(d))
  41.  
  42. //-------------------------------------------------------------------------
  43. //    Macro to truncate to the actual view (Windows coords can be off the 
  44. //    screen, but AVK coords can't.
  45. //-------------------------------------------------------------------------
  46.  
  47. #define    TRUNC(x, y)            (max(min((x), (y) - 1), 0))
  48.  
  49. //-------------------------------------------------------------------------     
  50. //FUNCTION:                                                                     
  51. //    
  52. //    VOID WinRect2AvkBox(pWinRect, pAvkBox, pView)
  53. //
  54. //PARMS IN:
  55. //
  56. //    RECT    *pWinRect;        Window's rectangle with window coordinates
  57. //                                as absolute screen coordinates (NOT 
  58. //                                relative to the window frame!).
  59. //    BOX        *pAvkBox;        Box to be set to the AVK coordinates that
  60. //                                correspond to pWinRect's screen coordinates
  61. //    VIEW    *pView;            View control structure.
  62. //
  63. //DESCRIPTION:
  64. //
  65. //    Converts absolute screen coordinates to AVK plane coordinates.  The
  66. //    screen coordinates are based on the physical screen resolution (e.g.,
  67. //    640x480 for VGA or 1024x768 for XGA.  The coordinate system is the
  68. //    lower right quadrant of a Cartesian coordinate system where x=0,y=0 
  69. //    is the upper left corner of the screen and x=xres-1,y=yres-y is the 
  70. //    lower right corner.  AVK plane coordinates are determined by the
  71. //    x and y resolutions used to create the current View in AvkViewCreate().
  72. //    They are also based on the lower right Cartesian quadrant.
  73. //
  74. //    The conversion algorithm is:
  75. //
  76. //        Xavk = (int)((double)Xphys * ((double)Xviewres / (double)Xphysres))
  77. //        
  78. //-------------------------------------------------------------------------
  79.  
  80. VOID
  81. WinRect2AvkBox(RECT *pWinRect, BOX *pAvkBox, VIEW *pView)
  82. {
  83.     //    If the View's screen coordinates are set, then we have initialized
  84.     //    the View structur and we can set the destination box coordinates.
  85.  
  86.     if (pView->cxScreen)
  87.     {
  88.         //    Scale the Windows coordinates of the Windows rectangle to
  89.         //    AVK coordinates.
  90.  
  91.         pAvkBox->x1 = SCREEN2AVK(pWinRect->left,     pView->xDelta);
  92.         pAvkBox->y1 = SCREEN2AVK(pWinRect->top,     pView->yDelta);
  93.         pAvkBox->x2 = SCREEN2AVK(pWinRect->right,     pView->xDelta);
  94.         pAvkBox->y2 = SCREEN2AVK(pWinRect->bottom, pView->yDelta);
  95.  
  96.         //    Truncate the AVK coordinates to the actual screen size (the 
  97.         //    source Windows coords may have been offscreen).
  98.                                    
  99.         pAvkBox->x1 = TRUNC(pAvkBox->x1, pView->cxView);
  100.         pAvkBox->y1 = TRUNC(pAvkBox->y1, pView->cyView);
  101.         pAvkBox->x2 = TRUNC(pAvkBox->x2, pView->cxView);
  102.         pAvkBox->y2 = TRUNC(pAvkBox->y2, pView->cyView);
  103.  
  104.         //    If the bitmap format is a 9-bit subsampled format, we align
  105.         //    the destination box on 4-pixel boundaries and size it to
  106.         //    multiples of 4 pixels to avoid edge effects from trying to 
  107.         //    interpolate imcomplete U and V plane data.
  108.  
  109.         if (pView->BmFmt == AVK_YUV9)
  110.         {
  111.             //    Align the the upper left coordinates by rounding down to 
  112.             //    a multiple of 4 pixels.
  113.  
  114.             pAvkBox->x1 &= ~0x03;
  115.             pAvkBox->y1 &= ~0x03;
  116.  
  117.             //    Make the width and depth of the box multiples of 4 by 
  118.             //    rounding the lower right coordinates up to one less 
  119.             //    than a multiple of 4.
  120.  
  121.             pAvkBox->x2 |=  0x03;
  122.             pAvkBox->y2 |=  0x03;
  123.         }
  124.     }
  125.  
  126. }
  127.  
  128.